<?php
$this->pageTitle = 'Contact us '.$brand;
e($javascript->link('jquery'));
?>
<script>
    $(document).ready(function(){
        
       $('#ContactAddForm').submit(function(){
            $('#logoError').empty().append('Sending message ... ').show();
            var input_name = $('#EmailName').val();
            var input_email = $('#EmailEmail').val();
            var input_website = $('#EmailWebsite').val();
           var input_description = $('#EmailDescription').val();
            var input_user = '<?=$_SERVER["REMOTE_ADDR"]?>';
            
            if(input_description.length<1){$('#logoError').append('Failed. Please refresh your browser.<br />');}
            if(input_name.length<1){$('#logoError').append('Your name still empty<br />.');}
            if(input_email.length<1){$('#logoError').append('Your email still empty<br />.');}
            if(input_user.length<1){$('#logoError').append('Failed. Please refresh your browser.<br />');}
            if(input_description.length>0 || input_email.length>0 || input_name.length>0 || input_user.length>0){
               $.ajax({
                    type: "POST",
                    data: ({name: input_name,email:input_email,description:input_description,website:input_website,user:input_user}),
                    dataType: "json",
                    url: "<?=$baseUrl?>/contacts/add",

                    success: function(data){
                        $('#logoError').empty();
                        if(data.result){
                            $('#emailForm').fadeOut('slow',function(){
                                $('#ContactAddForm').empty();
                                $('#emailForm').empty();
                            });
                            $('#logoError').append('Thanks for your contacting. We will processed it..');
                            $('#EmailName').val('');
                            $('#EmailWebsite').val('');
                            $('#EmailEmail').val('');
                            $('#EmailDescription').val('');
                        }else if(data.error){
                            if(data.error == '0'){
                                $('#logoError').append('Some form still empty.');
                            }else if(data.error == '1'){
                                $('#logoError').append('You have same contact before.<br />');
                            }else if(data.error == '2'){
                                $('#logoError').append('Failed saving. Please try again.<br />');
                            }else if (data.error.email == '1'){
                                $('#logoError').append('Your email is not valid.');
                            }else{
                                $('#logoError').append('Failed. Please refresh your browser.<br />');
                            }
                        }else{
                            $('#logoError').append('Please check your connection<br />');
                        }
                    },
                    error:function(XMLHttpRequest,textStatus, errorThrown)
                    {
                        var status = XMLHttpRequest.status;
                        if(status == '403'){
                           $('#logoError').empty().append('Please check your connection<br />');
                        }
                    }
                });
            }else{
                $('#logoError').append('Failed. Please refresh your browser.<br />');
            }
            
            return false;
        });
    });
</script>

<div id="contact">
    <div id="about-title">
        <h1> Wanna hire a professional logo creator and website developer?</h1>
    </div>

    <div id="contact-logo">
        <?=$form->create('Contact',array('action'=>'add'))?>
        <?=$form->input('Email.name',array('label'=>'Name * <br />','div'=>'text','size'=>'30'))?>
        <?=$form->input('Email.email',array('label'=>'Email * <br />','div'=>'text','size'=>'30'))?>
        <?=$form->input('Email.website',array('label'=>'Website (optional) <br />','div'=>'text','size'=>'30'))?>
        <?=$form->textarea('Email.description',array('label'=>false,'cols'=>'70','rows'=>'10'))?>
        <?=$form->end('submit')?>
          <div id="logoError" style="display:none;"></div>
    </div>  
</div>